import Vue from 'vue'
import Vuex from 'vuex'
import { setTokenObj, getTokenObj } from '../utils/storage.js'

Vue.use(Vuex)

const TOKEN_OBJ = getTokenObj() || {}
export default new Vuex.Store({
  state: {
    tokenInfo: {
      token: TOKEN_OBJ.token || '',
      refresh_token: TOKEN_OBJ.token || ''
    }
  },
  mutations: {
    mSetTokenInfo (state, newTokenInfo) {
      state.tokenInfo = newTokenInfo

      setTokenObj(newTokenInfo)
    }
  },
  actions: {
  },
  modules: {
    userInfo: {
      namespaced: true,
      state: {
        birthday: '',
        gender: '',
        id: '',
        mobile: '',
        name: '',
        photo: ''
      },
      mutations: {
        mSetUserInfo (state, newUserInfo) {
          state.birthday = newUserInfo.birthday
          state.gender = newUserInfo.gender
          state.id = newUserInfo.id
          state.mobile = newUserInfo.mobile
          state.name = newUserInfo.name
          state.photo = newUserInfo.photo
        }
      }
    }
  }
})
